import 'package:book_manager_app/app/utils/widget/input_value.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:book_manager_app/app/utils/common/result_code.dart';
import '../../../utils/widget/common.dart';
import '../../../utils/widget/layout_refresh_view.dart';
import '../controllers/add_book_controller.dart';

class AddBookView extends GetView<AddBookController> {
  const AddBookView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey.shade200,
      appBar: AppBar(
        title: const NavigationTitle(title: '补货/新增'),
        // actions: [
        //   NavigatorItem(text: "补货", onTap: ()=> Get.toNamed("/View"))
        // ],
      ),
      body: Column(children: [
        Obx(() => buildLoadingView()),
      ]),
      bottomNavigationBar: pageBottomButton(title: "保存", onPressed: ()=>controller.submit()),
    );
  }

  Widget buildLoadingView() {
    return LayoutRefreshView(
      state: controller.state.value,
      // onRefresh: controller.onRefresh,
      // controller: controller.refreshCtrl,
      child: setupListView(),
    );
  }

  Widget setupListView() {
    return ListView(
      padding: const EdgeInsets.fromLTRB(20, 10, 20, 0),
      keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
      children: [
        InputValue("书名：", "请输入书名", tec: controller.nameVC, required: true, keyboardType: TextInputType.phone, decoration: BoxDecorationRadius.topRadius()),
        InputValue("书号：", "请输入书号", tec: controller.isbnVC, required: true),
        InputValue("作者：", "请输入作者", tec: controller.authorVC, keyboardType: TextInputType.phone, required: true),
        // InputValue(title: "分类：", hintText: "请输入分类", vc: controller.categoryVC),
        InputValue("出版社：", "请输入出版社", tec: controller.pressVC, required: true,),
        InputValue("进价：", "请输入进价", tec: controller.originalPriceVC, required: true,),
        InputValue("售价：", "请输入售价", tec: controller.salePriceVC, required: true,),
        InputValue("库存：", "请输入库存", tec: controller.stockVC, required: true, keyboardType:TextInputType.numberWithOptions(), decoration: BoxDecorationRadius.bottomRadius()),
        const SizedBox(height: 5),
        ImageNetworking(controller.model.value.imageUrl??"", width: 200, height: 200),
      ],
    );
  }
}

